package site.qjdb.pojo;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * 	订单
 * 
 * */
public class Orders {
	private Integer oid; // 订单id
	private Date time; // 订单生成的时间
	private String realTotal; // 订单总额
	private Integer dbTotal; // 数据库中存储的订单总额
	private User user; // 订单所属用户
	private Integer state; // 订单状态，0：正常态

	public Orders() {
	}

	public int getOid() {
		return oid;
	}

	public void setOid(int oid) {
		this.oid = oid;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getRealTotal() {
		if (this.realTotal == null && this.dbTotal != null) {
			// 从数据库获取Integer类型数据，转成String类型。目的：用于前端显示
			Double _realTotal = this.dbTotal / 100d;
			// 0.00表示保留后两位，它的处理方式是直接截掉不要的尾数，不四舍五入。
			DecimalFormat df = new DecimalFormat("0.00");
			this.realTotal = df.format(_realTotal);
		}
		return realTotal;
	}

	public void setRealTotal(String realTotal) {
		this.realTotal = realTotal;
	}

	public Integer getDbTotal() {
		if (this.dbTotal == null && this.realTotal != null) {
			// 从web端获取String类型数据，转成Integer类型。目的：1.存储到数据库 2.进行运算
			BigDecimal bigDecimal = new BigDecimal(realTotal);
			Double _realTotal = bigDecimal.setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
			Double price = _realTotal * 100;
			this.dbTotal = price.intValue();
		}
		return dbTotal;
	}

	public void setDbTotal(Integer dbTotal) {
		this.dbTotal = dbTotal;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Override
	public String toString() {
		return "Order [oid=" + oid + ", time=" + time + ", realTotal=" + realTotal + ", dbTotal=" + dbTotal + ", user="
				+ user + ", state=" + state + "]";
	}

}
